#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QString>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    const int even_even=1;
    const int even0_odd1=2;
    const int even1_odd0=3;
    const int odd_odd=4;

  int curstate=even_even;
  QString str = ui->textEdit->toPlainText();
  int i=0;
  while(i<str.count())
  {
      if (str.at(i)=='1')
      {
          switch(curstate)
          {
              case(even_even):
                  curstate=even0_odd1;
                  break;
              case(even0_odd1):
                  curstate=even_even;
                  break;
              case(even1_odd0):
                  curstate=odd_odd;
                  break;
              case(odd_odd):
                  curstate=even1_odd0;
                  break;
          }
      }
      if (str.at(i)=='0')
      {
          switch(curstate)
          {
              case(even_even):
                  curstate=even1_odd0;
                  break;
              case(even0_odd1):
                  curstate=odd_odd;
                  break;
              case(even1_odd0):
                  curstate=even_even;
                  break;
              case(odd_odd):
                  curstate=even0_odd1;
                  break;
          }
      }
      i++;
  }
  if (curstate==even1_odd0)
      ui->textEdit_2->insertPlainText("OK");
  else
      ui->textEdit_2->insertPlainText("wrong string");
}
